<?php
if (isset($_POST['action'])) {
    switch ($_POST['action']) {
        case "Save Changes":
            $dataHash = showEmployeeInfo($_SESSION['userName'], $_SESSION['userPassHash'], $_POST['accName'])[2];
            $modifyEmployeeResult = modifyEmployee(
                    $_SESSION['userName'], 
                    $_SESSION['userPassHash'], 
                    $_POST['accName'], 
                    $dataHash, 
                    $_POST['empFname'], 
                    $_POST['empLname'], 
                    $_POST['startDate'], 
                    $_POST['endDate'], 
                    $_POST['empStatus'], 
                    $_POST['address'], 
                    $_POST['email'], 
                    $_POST['phoneNum'], 
                    $_POST['wage']);
            break;
        case "Delete Account":
            $accountHash = getAccount(
                    $_POST['accName'], 
                    $_SESSION['userName'], 
                    $_SESSION['userPassHash'])['results']['dataHash'];
            $deleteAccountResult = deleteAccount(
                    $_POST['accName'], 
                    $_SESSION['userName'], 
                    $_SESSION['userPassHash'], 
                    $accountHash);
            break;
    }
}

$allEmployeeInfo = getAllEmployeeDetails($_SESSION['userName'], $_SESSION['userPassHash']);
?>
<div class="accordion" id="employeesAccordion">
<?php
foreach ($allEmployeeInfo[1] as $employeeInfo) {
    ?><div class="accordion-group">
            <div class="accordion-heading">
              <a class="accordion-toggle" data-toggle="collapse" data-parent="#employeesAccordion"
                href="#<?php echo($employeeInfo['accName']); ?>"><?php echo($employeeInfo['accName']); ?></a></div>
        </div>
        <div <?php echo('id="' . $employeeInfo['accName'] . '"'); ?> class="accordion-body collapse">
            <div class="accordion-inner">
                <form action="" method="post">
                  <div class="controls controls-row">
                    <div class="control-group span3">
                      <label class="control-label" id="lblAccName<?php echo($employeeInfo['accName']); ?>" 
                        for="txtAccName<?php echo($employeeInfo['accName']); ?>">Account Name</label>
                      <div class="controls">
                        <input id="txtAccName<?php echo($employeeInfo['accName']); ?>" type="text" 
                        name="accName" value="<?php echo($employeeInfo['accName']); ?>" REQUIRED />     
                      </div>
                    </div>
                    <div class="control-group span3">
                      <label class="control-label" id="lblEmpFname<?php echo($employeeInfo['empFname']); ?>" 
                           for="txtEmpFname<?php echo($employeeInfo['empFname']); ?>">First Name</label>
                      <div class="controls">
                        <input id="txtEmpFname<?php echo($employeeInfo['empFname']); ?>" type="text" 
                           name="empFname" value="<?php echo($employeeInfo['empFname']); ?>" REQUIRED />
                      </div>      
                    </div>
                    <div class="control-group span3">
                      <label class="control-label" id="lblEmpLname<?php echo($employeeInfo['empLname']); ?>" 
                           for="txtEmpLname<?php echo($employeeInfo['empLname']); ?>">Last Name</label>
                      <div class="controls">
                        <input id="txtEmpLname<?php echo($employeeInfo['empLname']); ?>" type="text" 
                           name="empLname" value="<?php echo($employeeInfo['empLname']); ?>" REQUIRED />
                      </div>      
                    </div>
                  </div>
                  <div class="controls controls-row">
                    <div class="control-group span3">
                      <label id="lblStartDate<?php echo($employeeInfo['startDate']); ?>" 
                           for="txtStartDate<?php echo($employeeInfo['startDate']); ?>">Start Date</label>
                      <div class="controls">
                        <input class="datepicker span6" id="txtStartDate<?php echo($employeeInfo['startDate']); ?>" type="text" 
                           name="startDate" value="<?php echo($employeeInfo['startDate']); ?>" REQUIRED />
                      </div>
                    </div>
                    <div class="control-group span3">
                      <label id="lblEndDate<?php echo($employeeInfo['endDate']); ?>" 
                           for="txtEndDate<?php echo($employeeInfo['endDate']); ?>">End Date</label>
                      <div class="controls">
                        <input class="datepicker span6" id="txtEndDate<?php echo($employeeInfo['endDate']); ?>" type="text" 
                           name="endDate" value="<?php echo($employeeInfo['endDate']); ?>" />
                      </div>      
                    </div>
                    <div class="control-group span3">
                      <label id="lblEmpStatus<?php echo($employeeInfo['empStatus']); ?>" 
                           for="txtEmpStatus<?php echo($employeeInfo['empStatus']); ?>">Status</label>
                      <div class="controls">
                        <input class="span6" id="txtEmpStatus<?php echo($employeeInfo['empStatus']); ?>" type="text" 
                           name="empStatus" value="<?php echo($employeeInfo['empStatus']); ?>" REQUIRED />
                      </div>      
                    </div>
                  </div>
                  <div class="controls controls-row">
                    <div class="control-group span3">
                      <label id="lblAddress<?php echo($employeeInfo['address']); ?>" 
                           for="txtAddress<?php echo($employeeInfo['address']); ?>">Address</label>
                      <div class="controls">
                        <input id="txtAddress<?php echo($employeeInfo['address']); ?>" type="text" 
                           name="address" value="<?php echo($employeeInfo['address']); ?>" REQUIRED />
                      </div>
                    </div>
                    <div class="control-group span3">
                      <label id="lblEmail<?php echo($employeeInfo['email']); ?>" 
                           for="txtEmail<?php echo($employeeInfo['email']); ?>">Email</label>
                      <div class="controls">
                        <input id="txtEmail<?php echo($employeeInfo['email']); ?>" type="text" 
                           name="email" value="<?php echo($employeeInfo['email']); ?>" REQUIRED />
                      </div>      
                    </div>
                    <div class="control-group span3">
                      <label id="lblPhoneNum<?php echo($employeeInfo['phoneNum']); ?>" 
                           for="txtPhoneNum<?php echo($employeeInfo['phoneNum']); ?>">Phone Number</label>
                      <div class="controls">
                         <input id="txtPhoneNum<?php echo($employeeInfo['phoneNum']); ?>" type="text" 
                           name="phoneNum" value="<?php echo($employeeInfo['phoneNum']); ?>" REQUIRED />
                      </div>      
                    </div>
                  </div>
                  <div class="controls controls-row">
                    <div class="control-group span3">
                      <label id="lblWage<?php echo($employeeInfo['wage']); ?>" 
                           for="txtWage<?php echo($employeeInfo['wage']); ?>">Wage</label>
                      <div class="controls">
                         <input class="span4" id="txtWage<?php echo($employeeInfo['wage']); ?>" type="text" 
                           name="wage" value="<?php echo($employeeInfo['wage']); ?>" REQUIRED />
                      </div>      
                    </div>
                  </div>
                  <div class="control-group">
                    <div class="controls">
                      <input class="btn btn-primary" type="submit" name="action" value="Save Changes" />
                      <input class="btn" type="submit" name="action" value="Delete Account" />            
                    </div>
                  </div>
                </form>
            </div>
        </div>
    <?php
}
?>
</div>